use super::{app::AppConfig, db_pool::DBPool, redis_pool::RedisPool};
use crate::common::types::R2D2Pool;
use actix_web::web::Data;
use sea_orm::DatabaseConnection;

pub struct AppState {
    pub db: DatabaseConnection,
    pub redis: R2D2Pool,
}

impl AppState {
    pub async fn init(config: &AppConfig) -> Data<AppState> {
        let db = DBPool::init(config).await;
        let redis = RedisPool::init(config).await;
        Data::new(AppState { db, redis })
    }
}
